package com.example.myapplication.baidumap;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.baidu.mapapi.bikenavi.BikeNavigateHelper;
import com.baidu.mapapi.bikenavi.adapter.IBEngineInitListener;
import com.baidu.mapapi.bikenavi.adapter.IBRoutePlanListener;
import com.baidu.mapapi.bikenavi.model.BikeRoutePlanError;
import com.baidu.mapapi.bikenavi.params.BikeNaviLaunchParam;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.walknavi.WalkNavigateHelper;
import com.baidu.mapapi.walknavi.adapter.IWEngineInitListener;
import com.baidu.mapapi.walknavi.adapter.IWNaviCalcRouteListener;
import com.baidu.mapapi.walknavi.adapter.IWRoutePlanListener;
import com.baidu.mapapi.walknavi.model.WalkRoutePlanError;
import com.baidu.mapapi.walknavi.params.RouteNodeType;
import com.baidu.mapapi.walknavi.params.WalkNaviLaunchParam;
import com.baidu.mapapi.walknavi.params.WalkRouteNodeInfo;
import com.example.myapplication.R;

public class testActivity extends AppCompatActivity {
    private LatLng startPt;
    private LatLng endPt;
    private WalkNaviLaunchParam mParam;
    private BikeNaviLaunchParam param;
    private WalkNaviLaunchParam walkParam;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        //起终点位置
        startPt = new LatLng(40.056015,116.3078);// 百度大厦
        WalkRouteNodeInfo walkStartNode = new WalkRouteNodeInfo();
        walkStartNode.setKeyword("百度大厦");
        walkStartNode.setLocation(startPt);
        walkStartNode.setType(RouteNodeType.KEYWORD);
        walkStartNode.setCitycode(131);

        endPt = new LatLng(40.035919,116.339863);
        WalkRouteNodeInfo walkEndNode = new WalkRouteNodeInfo();
        walkEndNode.setLocation(endPt);
        walkEndNode.setType(RouteNodeType.KEYWORD);
        walkEndNode.setKeyword("麻辣诱惑(五彩城店) ");
        walkEndNode.setBuildingID("1260176407175102463");
        walkEndNode.setFloorID("F4");
        walkEndNode.setCitycode(131);
        walkParam = new WalkNaviLaunchParam().startNodeInfo(walkStartNode).endNodeInfo(walkEndNode);

        //起终点位置
        startPt = new LatLng(40.047416, 116.312143);
        endPt = new LatLng(40.048424, 116.313513);
        //构造WalkNaviLaunchParam
        mParam = new WalkNaviLaunchParam().stPt(startPt).endPt(endPt);
        //构造BikeNaviLaunchParam
        //.vehicle(0)默认的普通骑行导航
        param = new BikeNaviLaunchParam().stPt(startPt).endPt(endPt).vehicle(0);

        // 获取导航控制类

//        walkengineInit();
        bickengineInit();

    }

    // 骑行引擎初始化
    public  void bickengineInit(){
        BikeNavigateHelper.getInstance().initNaviEngine(this, new IBEngineInitListener() {
            @Override
            public void engineInitSuccess() {
                //骑行导航初始化成功之后的回调
                bikeroutePlanWithParam();
            }

            @Override
            public void engineInitFail() {
                //骑行导航初始化失败之后的回调
            }
        });
    }
    // 步行引擎初始化
    public void walkengineInit(){
        WalkNavigateHelper.getInstance().initNaviEngine(this, new IWEngineInitListener() {

            @Override
            public void engineInitSuccess() {
                //引擎初始化成功的回调
                walkroutePlanWithParam();
                Log.i("xx","引擎初始化成功的回调");
            }

            @Override
            public void engineInitFail() {
                //引擎初始化失败的回调
                Log.i("xx","引擎初始化失败的回调");
            }
        });
    }


    public void bikeroutePlanWithParam (){
//        发起算路
        BikeNavigateHelper.getInstance().routePlanWithParams(param, new IBRoutePlanListener() {
            @Override
            public void onRoutePlanStart() {
                //执行算路开始的逻辑
            }

            @Override
            public void onRoutePlanSuccess() {
                //算路成功
                //跳转至诱导页面
                Intent intent = new Intent(testActivity.this, WNaviGuideActivity.class);
                startActivity(intent);
            }

            @Override
            public void onRoutePlanFail(BikeRoutePlanError bikeRoutePlanError) {
                //执行算路失败的逻辑
            }
        });
    }

    public void walkroutePlanWithParam (){
//      发起算路
        WalkNavigateHelper.getInstance().routePlanWithParams(mParam, new IWRoutePlanListener() {
            @Override
            public void onRoutePlanStart() {
                //开始算路的回调
                Log.i("xx","开始算路的回调");
            }

            @Override
            public void onRoutePlanSuccess() {
                Log.i("xx","算路成功");
                //算路成功
                //跳转至诱导页面
                Intent intent = new Intent(testActivity.this, WNaviGuideActivity.class);
                startActivity(intent);
            }

            @Override
            public void onRoutePlanFail(WalkRoutePlanError walkRoutePlanError) {
                Log.i("xx","算路失败的回调");
                //算路失败的回调
            }
        });
    }

    //导航引擎算路
    private void naviCalcRoute(int routeIndex) {
        WalkNavigateHelper.getInstance().naviCalcRoute(routeIndex, new IWNaviCalcRouteListener() {
            @Override
            public void onNaviCalcRouteSuccess() {
                Intent intent = new Intent();
                intent.setClass(testActivity.this, WNaviGuideActivity.class);
                startActivity(intent);
            }

            @Override
            public void onNaviCalcRouteFail(WalkRoutePlanError error) {
                Log.d("xx", "WalkNavi naviCalcRoute fail");
            }
        });
    }
}